#! /bin/bash

set -e
set -x

export SIMPATH="@CMAKE_INSTALL_PREFIX@"
version="@TEST_VERSION@"
sourcedir=FairRoot_${version}
git clone -b ${version} https://github.com/FairRootGroup/FairRoot $sourcedir
pushd $sourcedir
mkdir -p build/install
export FAIRROOTPATH="$(realpath ./build/install)"
cmake -S. -Bbuild \
  -DCMAKE_INSTALL_PREFIX=$FAIRROOTPATH
cmake --build build --target install -j @NCPUS@
pushd build
ctest --output-on-failure -E "(ex_MQ_pixel|pixelSplitDDS).*" -j @NCPUS@ $(ctest --version | grep -q "3\.16" || echo "--repeat until-pass:5")
popd
